﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CVS_log_parser
{
    class PropsDictionary
    {
        string[] props;

        public PropsDictionary(string rawString, params string[] delimiters)
        {
            this.props = rawString.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
        }

        public PropsDictionary(string rawString) : this(rawString, Environment.NewLine, ";" + Environment.NewLine, ";  ") { }

        public string this[string name]
        {
            get
            {
                return GetValue(name, new string[] { ": " });
            }
        }

        public string GetValue(string name, params string[] delimiters)
        {
            name = name.Trim().ToUpper();

            var prop = this.props.FirstOrDefault(x => delimiters.Any(y => x.ToUpper().StartsWith(name + y)));
            var theDelimiter = delimiters.FirstOrDefault(x => prop != null && prop.Contains(x));

            if ( theDelimiter == null )
                return string.Empty;

            return prop.Substring(prop.IndexOf(theDelimiter) + theDelimiter.Length);
        }
    }
}
